package com.czl.module_service.adapter

import android.os.Bundle
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.czl.base.binding.command.BindingCommand
import com.czl.base.binding.command.BindingConsumer
import com.czl.base.config.AppConstants
import com.czl.base.data.bean.tengyun.PurchaseBean
import com.czl.module_service.R
import com.czl.module_service.databinding.ItemMyApplyPurchaseBinding
import com.czl.module_service.fragment.purchase.PurchaseMyApplyFragment

class PurchaseApplyAdapter(private val fragment: PurchaseMyApplyFragment) :
    BaseQuickAdapter<PurchaseBean, BaseDataBindingHolder<ItemMyApplyPurchaseBinding>>(
        R.layout.item_my_apply_purchase
    ) {

    private var taskUserId : String = ""
    var tabIndex : Int = 1

    override fun convert(
        holder: BaseDataBindingHolder<ItemMyApplyPurchaseBinding>,
        item: PurchaseBean,
    ) {
        holder.dataBinding?.run {
            data = item
            adapter = this@PurchaseApplyAdapter
            executePendingBindings()
        }
    }

    val onItemClick: BindingCommand<Any> = BindingCommand(BindingConsumer {
        if (it is PurchaseBean) {
            taskUserId = if (tabIndex == 2 && it.processStatus == 1 && it.ttStatus == 2 && it.taskUserId != null) {
                it.taskUserId.toString()
            } else {
                ""
            }
            val bundle = Bundle()
            bundle.putString("applicaitonId", it.applicaitonId.toString())
            bundle.putString("tabIndex", tabIndex.toString())
            bundle.putString("taskUserId", taskUserId)
            fragment.startContainerActivity(AppConstants.Router.Service.F_SERVICE_PURCHASE_APPLY_INFO, bundle)
        }
    })
}
